package Thread;

import java.util.concurrent.*;

public class MyThreadPool1 {
    public static void main(String[] args) {
        //ExecutorService pool = Executors.newFixedThreadPool(5);
       // ExecutorService pool = Executors.newSingleThreadExecutor();
       //ExecutorService pool = Executors.newCachedThreadPool();
        ExecutorService pool = new ThreadPoolExecutor(
                3,
                5,
                10L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        try {
            for (int i=1;i<=10;i++){
                pool.execute(()->{
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"办理业务");
                });
            }
        }finally {
            pool.shutdown();
        }
    }
}
/*
pool-1-thread-1办理业务
pool-1-thread-3办理业务
pool-1-thread-2办理业务
pool-1-thread-4办理业务
pool-1-thread-3办理业务
pool-1-thread-2办理业务
pool-1-thread-3办理业务
pool-1-thread-4办理业务
pool-1-thread-3办理业务
pool-1-thread-4办理业务

Process finished with exit code 0

 */